package com.ltkj.shop.service.impl;

import java.util.List;
import java.util.stream.Collectors;

import com.ltkj.common.core.utils.DateUtils;
import com.ltkj.common.core.utils.StringUtils;
import com.ltkj.common.datascope.annotation.DataScope;
import com.ltkj.common.security.utils.SecurityUtils;
import com.ltkj.shop.domain.ShopHotelRoom;
import com.ltkj.shop.domain.vo.ShopHotelRoomVo;
import com.ltkj.shop.domain.vo.ShopHotelVo;
import com.ltkj.shop.mapper.ShopHotelBizMapper;
import com.ltkj.shop.mapper.ShopHotelRoomBizMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ltkj.shop.mapper.ShopHotelMapper;
import com.ltkj.shop.domain.ShopHotel;
import com.ltkj.shop.service.IShopHotelService;

/**
 * 酒店商户Service业务层处理
 * 
 * @author xupf
 * @date 2023-08-29
 */
@Service
public class ShopHotelServiceImpl implements IShopHotelService 
{
    @Autowired
    private ShopHotelMapper shopHotelMapper;
    @Autowired
    private ShopHotelBizMapper shopHotelBizMapper;
    @Autowired
    private ShopHotelRoomBizMapper shopHotelRoomBizMapper;

    /**
     * 查询酒店商户
     * 
     * @param id 酒店商户主键
     * @return 酒店商户
     */
    @Override
    public ShopHotelVo selectShopHotelById(Long id)
    {
        return shopHotelBizMapper.selectShopHotelById(id);
    }

    /**
     * 移动端查询酒店商户
     *
     * @param shopHotel 酒店商户
     * @return 酒店商户
     */
    @Override
    public List<ShopHotelVo> selectList(ShopHotel shopHotel) {
        // 查询营业中酒店
        shopHotel.setStatus("1");
        List<ShopHotelVo> shopHotelVos = shopHotelBizMapper.selectList(shopHotel);
        if (StringUtils.isNull(shopHotel.getParams().get("limit"))) {
            for (ShopHotelVo shopHotelVo : shopHotelVos) {
                ShopHotelRoom shopHotelRoom = new ShopHotelRoom();
                shopHotelRoom.setHotelId(shopHotelVo.getId());
                List<ShopHotelRoom> shopHotelRooms = shopHotelRoomBizMapper.selectShopHotelRoomList(shopHotelRoom);
                shopHotelVo.setHotelRoomVos(shopHotelRooms.stream().map(ShopHotelRoomVo::fromDO).collect(Collectors.toList()));
            }
        }
        return shopHotelVos;
    }

    /**
     * 查询酒店商户列表
     * 
     * @param shopHotel 酒店商户
     * @return 酒店商户
     */
    @Override
    @DataScope(storeAlias = "h")
    public List<ShopHotelVo> selectShopHotelList(ShopHotel shopHotel)
    {
        return shopHotelBizMapper.selectShopHotelList(shopHotel);
    }

    /**
     * 新增酒店商户
     * 
     * @param shopHotel 酒店商户
     * @return 结果
     */
    @Override
    public ShopHotel insertShopHotel(ShopHotel shopHotel)
    {
        shopHotel.setCreateTime(DateUtils.getNowDate());
        shopHotel.setCreateBy(SecurityUtils.getLoginUser().getUsername());
        shopHotel.setUserId(SecurityUtils.getLoginUser().getUserid());
        shopHotel.setIsDel("0");
        shopHotel.setStatus("1");
        shopHotelMapper.insertShopHotel(shopHotel);
        return shopHotel;
    }

    /**
     * 修改酒店商户
     * 
     * @param shopHotel 酒店商户
     * @return 结果
     */
    @Override
    public int updateShopHotel(ShopHotel shopHotel)
    {
        shopHotel.setUpdateTime(DateUtils.getNowDate());
        shopHotel.setUpdateBy(SecurityUtils.getLoginUser().getUsername());
        return shopHotelMapper.updateShopHotel(shopHotel);
    }

    /**
     * 批量删除酒店商户
     * 
     * @param ids 需要删除的酒店商户主键
     * @return 结果
     */
    @Override
    public int deleteShopHotelByIds(Long[] ids)
    {
        return shopHotelBizMapper.deleteShopHotelByIds(ids);
    }

    /**
     * 删除酒店商户信息
     * 
     * @param id 酒店商户主键
     * @return 结果
     */
    @Override
    public int deleteShopHotelById(Long id)
    {
        return shopHotelBizMapper.deleteShopHotelById(id);
    }
}
